package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.itheima.common.domain.AjaxResult;
import com.itheima.order.entity.OmsOrderSetting;
import com.itheima.service.OmsOrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//关于后端订单设置
@Slf4j
@RestController
@RequestMapping("/orderSetting")
public class OmsOrderSettingController {

    @Autowired
    private OmsOrderSettingService omsOrderSettingService;

    /**
     * 修改指定订单设置
     *
     * @param id
     * @param omsOrderSetting
     * @return
     */
    @PostMapping("/update/{id}")
    public AjaxResult updateById(@PathVariable Long id, @RequestBody OmsOrderSetting omsOrderSetting) {
        LambdaUpdateWrapper<OmsOrderSetting> luw = new LambdaUpdateWrapper<>();
        luw.eq(OmsOrderSetting::getId, id)
                .set(omsOrderSetting.getCommentOvertime() != null, OmsOrderSetting::getCommentOvertime, omsOrderSetting.getCommentOvertime())
                .set(omsOrderSetting.getConfirmOvertime() != null, OmsOrderSetting::getConfirmOvertime, omsOrderSetting.getConfirmOvertime())
                .set(omsOrderSetting.getFinishOvertime() != null, OmsOrderSetting::getFinishOvertime, omsOrderSetting.getFinishOvertime())
                .set(omsOrderSetting.getFlashOrderOvertime() != null, OmsOrderSetting::getFlashOrderOvertime, omsOrderSetting.getFlashOrderOvertime())
                .set(omsOrderSetting.getNormalOrderOvertime() != null, OmsOrderSetting::getNormalOrderOvertime, omsOrderSetting.getNormalOrderOvertime());
        omsOrderSettingService.update(luw);
        return AjaxResult.success();
    }

    /**
     * 获取指定的订单
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AjaxResult getById(@PathVariable Long id) {
        OmsOrderSetting omsOrderSetting = omsOrderSettingService.getById(id);
        return AjaxResult.success(omsOrderSetting);
    }
}
